class Mymeta(type): #必须继承type
    def __init__(cls, *args, **kwargs):
        super().__init__(*args, **kwargs)
        print('===>Mymeta.__init__')
        print(cls.__name__)
        print(args)
        print(kwargs)
        print(cls.yaml_tag) #这里可以拿到Foo 里的yaml_tag

    def __new__(mcs, *args, **kwargs):
        print('===>Mymeta.__new__')
        print(mcs.__name__)
        return type.__new__(mcs, *args, **kwargs)

    def __call__(cls, *args, **kwargs):  # 对Foo的改造都在__call__这里
        print('===>Mymeta.__call__')
        cls.__init__(cls, *args, **kwargs)
        obj = cls.__new__(cls)
        return obj


class Foo(metaclass=Mymeta): # metaclass=Mymeta 注明metaclass用这个重构
    yaml_tag = '!Foo'

    def __init__(self, name):
        print('Foo.__init__')
        self.name = name
        print(f'name,也就是入参:{name}')

    def __new__(cls, *args, **kwargs):
        print('Foo.__new__')
        return object.__new__(cls)


if __name__ == '__main__':
    foo = Foo('foo')
    # foo = Foo()


# ===>Mymeta.__new__
# Mymeta
# ===>Mymeta.__init__
# Foo
# ('Foo', (), {'__module__': '__main__', '__qualname__': 'Foo', 'yaml_tag': '!Foo', '__init__': <function Foo.__init__ at 0x0376DDF8>, '__new__': <function Foo.__new__ at 0x0376DDB0>})
# {}
# !Foo
# ===>Mymeta.__call__
# Foo.__init__  ！！！！！！！重要：：：这里，就把init提前到new了
# name:foo
# Foo.__new__
